package com.songlanyun.modules.servicegoods.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.group.entity.ProductGoodsGroupEntity;
import com.songlanyun.modules.servicegoods.model.dto.ServiceGoodsGroupDTO;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.servicegoods.entity.ServiceGoodsGroup;
import com.songlanyun.modules.servicegoods.service.ServiceGoodsGroupService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;



/**
 * 商家的服务分组，只用来在商家店铺内展示
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2020-12-15 11:51:34
 */
@RestController
@RequestMapping("admin/servicegoods/group")
public class ServiceGoodsGroupAdminController extends AbstractController {
    @Autowired
    private ServiceGoodsGroupService serviceGoodsGroupService;

    /**
     * 所有商家的服务分组
     */
    @RequestMapping("/all")
    //@RequiresPermissions("shop:goods_group:all")
    public R all(){
        List<Map<String, Object>> objs = serviceGoodsGroupService.getAllGoodsGroup(this.getShopId(true));
        return R.ok().put("list", objs);
    }


    /**
     * 商家的服务分组信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("servicegoods:servicegoodsgroup:info")
    public R info(@PathVariable("id") Long id){
        ServiceGoodsGroup serviceGoodsGroup = serviceGoodsGroupService.getByShopIdAndId(getShopId(true),id);
        return R.ok().put("data", serviceGoodsGroup);
    }


    /**
     * 商家的服务分组创建
     */
    @SysLog("商家的服务分组创建")
    @PostMapping("/create")
    //@RequiresPermissions("servicegoods:servicegoodsgroup:save")
    public R create(@RequestBody ServiceGoodsGroupDTO dto){
        ServiceGoodsGroup obj = serviceGoodsGroupService.add(getShopId(), dto);
        return R.ok().put("data",obj);
    }

    /**
     * 商家的服务分组修改
     */
    @SysLog("商家的服务分组修改")
    @PutMapping("/update")
    //@RequiresPermissions("servicegoods:servicegoodsgroup:update")
    public R update(@RequestBody ServiceGoodsGroupDTO dto){
        ServiceGoodsGroup obj = serviceGoodsGroupService.update(getShopId(), dto);
        return R.ok().put("data",obj);
    }


    /**
     * 商家的服务分组删除
     */
    @SysLog("商家的服务分组删除")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("group:productgoodsgroup:update")
    public R delete(@PathVariable("id") Long id){
        serviceGoodsGroupService.deleteByShopIdAndId(this.getShopId(),id);
        return R.ok();
    }

    /**
     * 第一级服务商品分组
     */
    @RequestMapping("/first")
    //@RequiresPermissions("system:category:all")
    public R first(){
        List<ServiceGoodsGroup> objs = serviceGoodsGroupService.getFirstProductGoods(this.getShopId());
        return R.ok().put("list", objs);
    }


}
